import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { DelDataButton, ExamineFillButton, ExecuteButton, MonitorVideoButton, ModDataButton } from '../Common/options'
import { LabHandleType, ProjectList } from '../Common/Conversion'

export const LabPmsTesterCbr = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    const labHandleType = await LabHandleType()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'testDate@desc' },
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'LabPmsTesterCbr' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'taskNo',
                title: '试验编号(组号)',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'sampleName',
                title: '样品名称',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'testFr',
                title: '试件序号',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'sampleNo',
                title: '试样编号',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'startTime',
                title: '开始时间',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'cbr25',
                title: 'CBR25(%)',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'cbr50',
                title: 'CBR50(%)',
                valueType: 'input',
                width: 150,
            },

            {
                dataIndex: 'result',
                title: '评定结果',
                valueType: 'input',
                render: (_, e) => <div>{e.result === 0 ? '合格' : e.result === 1 ? '不合格' : '未评定'}</div>,
                width: 150,
            },
            {
                dataIndex: 'labHandleTypeUuid',
                title: '处理意见',
                valueType: 'select',
                ellipsis: true,
                valueEnum: labHandleType,
                width: 180,
            },
            {
                dataIndex: 'remark',
                title: '意见说明',
                valueType: 'input',
                width: 180,
                hideInSearch: true,
            },
            {
                dataIndex: 'handleUserName',
                title: '审核人',
                valueType: 'input',
                width: 180,
                hideInSearch: true,
            },
            {
                dataIndex: 'handleTime',
                title: '审核时间',
                valueType: 'input',
                width: 180,
                hideInSearch: true,
            },

            { ...commonTableList.isEnabled, rules: true, hideInSearch: false },
            {
                dataIndex: 'equipmentNumber',
                title: '设备编号',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'equipmentName',
                title: '设备名称',
                valueType: 'input',
                width: 400,
                hideInSearch: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { originalDataTable, labHandleTypeUuid, isEnabled, groupId, endTime, startTime, testDate } =
                        record
                    return [
                        // <ModDataButton
                        //     OptionsEvent={OptionsEvent}
                        //     key="modify"
                        //     title="修改"
                        //     url={url}
                        //     data={record}
                        // />,
                        Permission.findIndex(v => v.uuid === '5780116d-a610-4244-9685-a159c11ae92d') !== -1 &&
                            !labHandleTypeUuid && (
                                <ExamineFillButton
                                    key="Examine"
                                    OptionsEvent={OptionsEvent}
                                    title="处理意见"
                                    data={{
                                        options: labHandleType,
                                        groupId,
                                        url: 'posLabPmsTesterCbrUpdateRemark',
                                        actionRef,
                                    }}
                                />
                            ),
                        ((endTime && startTime) || testDate) && (
                            <MonitorVideoButton
                                key="video"
                                title="监控画面"
                                OptionsEvent={OptionsEvent}
                                data={{
                                    url: 'getLabDataCameraByOriginalDataTable',
                                    originalDataTable,
                                    labHandleTypeUuid,
                                    startTime,
                                    endTime,
                                    testDate,
                                }}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '2669fd37-c81d-4d88-aece-b1d1d8c4ccb8') !== -1 &&
                            isEnabled !== 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="posLabPmsTesterCbrSetIsEnabled"
                                    path={[groupId, 1]}
                                    tips="数据启用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '2669fd37-c81d-4d88-aece-b1d1d8c4ccb8') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="禁用"
                                    danger={true}
                                    url="posLabPmsTesterCbrSetIsEnabled"
                                    path={[groupId, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '3e7db90a-4b79-4096-a85b-8462073ea1fa') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
